package com.mianshi;

import java.util.Scanner;

public class wangyi3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if(n == 0){
            System.out.println(0);
        }
        int num = dfs(n);
        System.out.println(dfs(n));
    }

    public static int dfs(int n){
        if(countOne(n) == 1){
            return 1;
        }
        int index = 1;
        while(Math.pow(2,index) <= n){
            index++;
        }
        return Math.min(countOne(n), 1+dfs((int) (Math.pow(2,index)-n)));
    }

    public static int countOne(int n){
        int ans = 0;
        while(n != 0){
            if((n & 1) == 1){
                ans++;
            }
            n >>>= 1;
        }
        return ans;
    }
}
